package org.elepower.controller;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.elepower.dao.InspectiontaskDetailsDao;
import org.elepower.dao.Inspectiontask_mainDao;
import org.elepower.dao.SolveDetailDao;
import org.elepower.dao.SolveMainDao;
import org.elepower.pojo.PsInspectiontaskDetails;
import org.elepower.pojo.PsInspectiontask_main;
import org.elepower.pojo.PsSolvetaskDetail;
import org.elepower.pojo.PsSolvetaskMain;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/statistical")
public class StatisticalController {
    @Autowired
    private InspectiontaskDetailsDao inspectiontaskDetailsDao;
    @Autowired
    private Inspectiontask_mainDao inspectiontask_mainDao;
    @Autowired
    private SolveMainDao solveMainDao;
    @Autowired
    private SolveDetailDao solveDetailDao;

    @RequestMapping("/inspection")
    public String inspection() throws Exception{
        return "system/statistical/inspectionIndex";
    }

    @RequestMapping("/solve")
    public String solve() throws Exception{
        return "system/statistical/solveIndex";
    }

    @RequestMapping("/inspectionTaskList")
    @ResponseBody
    public Map<String, Object> inspectionTaskList(@RequestParam(defaultValue = "1") Integer page, @RequestParam(defaultValue = "10") Integer limit, PsInspectiontaskDetails psInspectiontaskDetails,PsInspectiontask_main psInspectiontask_main) throws Exception {

        Map<String, Object> map = new HashMap<>();
        Page<PsInspectiontaskDetails> pager = PageHelper.startPage(page,limit);
        System.out.println(psInspectiontask_main.getInspectionTaskCode());
        psInspectiontaskDetails.setPsInspectiontask_main(psInspectiontask_main);
        List<PsInspectiontaskDetails> list = inspectiontask_mainDao.inspectionStatistical(psInspectiontaskDetails);
        map.put("code", 0);
        map.put("msg", "");
        map.put("data", list);
        map.put("count", pager.getTotal());
        return map;
    }


    @RequestMapping("/solveTaskList")
    @ResponseBody
    public Map<String, Object> solveTaskList(@RequestParam(defaultValue = "1") Integer page, @RequestParam(defaultValue = "10") Integer limit, PsSolvetaskDetail condition, PsInspectiontask_main psInspectiontask_main,PsInspectiontaskDetails psInspectiontaskDetails, PsSolvetaskMain psSolvetaskMain) throws Exception {

        Map<String, Object> map = new HashMap<>();
        Page<PsSolvetaskDetail> pager = PageHelper.startPage(page,limit);
        condition.setPsInspectiontask_main(psInspectiontask_main);
        condition.setPsSolvetaskMain(psSolvetaskMain);
        condition.setPsInspectiontaskDetails(psInspectiontaskDetails);
        List<PsSolvetaskDetail> list = inspectiontask_mainDao.solveStatistical(condition);
        map.put("code", 0);
        map.put("msg", "");
        map.put("data", list);
        map.put("count", pager.getTotal());
        return map;
    }

}
